package com.ruoyi.parking.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.parking.domain.ParkOrder;
import com.ruoyi.parking.dto.OrderAndCar;
import com.ruoyi.parking.service.IParkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单信息Controller
 * 
 * @author chenkai
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/parking/order")
public class ParkOrderController extends BaseController
{
    @Autowired
    private IParkOrderService parkOrderService;

    /**
     * 查询订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('parking:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderAndCar orderAndCar)
    {
        startPage();
        List<OrderAndCar> list = parkOrderService.selectParkOrderList(orderAndCar);
        System.out.println("=======================48"+list);
        return getDataTable(list);
    }

    /**
     * 导出订单信息列表
     */
//    @PreAuthorize("@ss.hasPermi('parking:order:export')")
//    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ParkOrder parkOrder)
//    {
//        List<ParkOrder> list = parkOrderService.selectParkOrderList(parkOrder);
//        ExcelUtil<ParkOrder> util = new ExcelUtil<ParkOrder>(ParkOrder.class);
//        util.exportExcel(response, list, "订单信息数据");
//    }

    /**
     * 获取订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Integer orderId)
    {
        return success(parkOrderService.selectParkOrderByOrderId(orderId));
    }

    /**
     * 新增订单信息
     */
    @PreAuthorize("@ss.hasPermi('parking:order:add')")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkOrder parkOrder)
    {
        return toAjax(parkOrderService.insertParkOrder(parkOrder));
    }

    /**
     * 修改订单信息
     */
    @PreAuthorize("@ss.hasPermi('parking:order:edit')")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkOrder parkOrder)
    {
        return toAjax(parkOrderService.updateParkOrder(parkOrder));
    }

    /**
     * 删除订单信息
     */
    @PreAuthorize("@ss.hasPermi('parking:order:remove')")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Integer[] orderIds)
    {
        return toAjax(parkOrderService.deleteParkOrderByOrderIds(orderIds));
    }
}
